package com.kalaqia.image.glide;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.signature.ObjectKey;

/**
 * @author kalaqia 421407393@qq.com
 */
public class ImageModelLoader implements ModelLoader<String, String> {

    @Nullable
    @Override
    public LoadData<String> buildLoadData(@NonNull String s, int width, int height, @NonNull Options options) {
        return new LoadData<>(new ObjectKey(s), new ImageDataFetcher(s));
    }

    @Override
    public boolean handles(@NonNull String s) {

        //检查路径是否是标准网络格式
        boolean startCheck = !s.startsWith("http://") && !s.startsWith("https://");

        //目前支持的格式
        boolean imgFormat = s.endsWith(".jpg") || s.endsWith(".png");

        return startCheck && imgFormat;
    }

}
